'--------------------------------------------------------
' 执行所有测试用例
'--------------------------------------------------------
Private Sub test_SeparateOneSheetEntityManager_ALL_case()
    '--------------------
    ' 测试: entity 名转换
    '--------------------
    ' getEntityLogicName
    ' 测试: 使用 entity 的物理名来获取 entity 的逻辑名
    test_SeparateOneSheetEntityManager_getEntityLogicName
    ' getEntityPhyName
    ' 测试: 使用 entity 的逻辑名来获取 entity 的物理名
    test_SeparateOneSheetEntityManager_getEntityPhyName

    '--------------------
    ' 测试: item 名转换
    '--------------------
    ' getItemPhyName
    ' 测试: 使用 item 逻辑名，获取 item 物理名
    test_SeparateOneSheetEntityManager_getItemPhyName
    ' getItemPhyNameByEntityPhyName
    ' 测试: 使用 item 逻辑名 + entity 物理名，获取 item  物理名
    test_SeparateOneSheetEntityManager_getItemPhyNameByEntityPhyName
    ' getItemPhyNameByEntityLogicName
    ' 测试: 使用 item 逻辑名 + entity 逻辑名，获取 item 物理名
    test_SeparateOneSheetEntityManager_getItemPhyNameByEntityLogicName
    ' getItemLogicName
    ' 测试: 使用 item 物理名获取 item 逻辑名
    test_SeparateOneSheetEntityManager_getItemLogicName
    ' getItemLogicNameByEntityPhyName
    ' 测试: 使用 item 物理名 + entity 逻辑名，获取 item 逻辑名
    test_SeparateOneSheetEntityManager_getItemLogicNameByEntityPhyName
    ' getItemLogicNameByEntityLogicName
    ' 测试: 使用 item 物理名 + entity 物理名，获取 item 逻辑名
    test_SeparateOneSheetEntityManager_getItemLogicNameByEntityLogicName

    '--------------------
    ' 测试: item 名称类型检查
    '--------------------
    ' 检查当前的 item 是不是逻辑名
    test_SeparateOneSheetEntityManager_isLogicItemNameByEntityLogicName
    ' 检查当前的 item 是不是物理名
    test_SeparateOneSheetEntityManager_isPhyItemNameByEntityPhyName

    '--------------------
    ' 获取 item 名称
    '--------------------
    ' 获取 item 物理名 + 使用 entity 物理名
    test_SeparateOneSheetEntityManager_getItemPhyNames_by_entityPhyName
    ' 获取 item 物理名 + 使用 entity 逻辑名
    test_SeparateOneSheetEntityManager_getItemPhyNames_by_entityLogicName
    ' 获取 item 逻辑名 + 使用 entity 物理名
    test_SeparateOneSheetEntityManager_getItemLogicNames_by_entityPhyName
    ' 获取 item 逻辑名 + 使用 entity 逻辑名
    test_SeparateOneSheetEntityManager_getItemLogicNames_by_entityLogicName
End Sub

'----------------------------------------------------------------
' test common
'----------------------------------------------------------------
' TODO
' 如果不存在测试 sheet，需要手动创建一个
Private Sub create_SeparateOneSheetEntityManager_test_sheet()
End Sub

Private Function create_SeparateOneSheetEntityManager() As ISqlEntityManager
    Dim oneSheetEntityManager As SeparateOneSheetEntityManager
    Set oneSheetEntityManager = New SeparateOneSheetEntityManager

    ' 1. 需要提供两个管理 sheet 对象
    Dim entityInfoSheet As WorkSheet
    Set entityInfoSheet = Sheets("entityList")
    Dim itemInfoSheet As WorkSheet
    Set itemInfoSheet = Sheets("entityItems")

    ' 2. 执行初始化
    oneSheetEntityManager.Init _
        entityInfoSheet, _
        itemInfoSheet, _
        entityInfoStartRow:= 4, _
        entityLogicNameCol:= "C", _
        entityPhyNameCol:= "D", _
        itemInfoStartRow:= 4, _
        itemPhyNameCol:= "D", _
        itemLogicNameCol:= "C", _
        itemEntityLogicNameCol:= "B"

    Set create_SeparateOneSheetEntityManager = oneSheetEntityManager
End Function

'----------------------------------------------------------------
' 测试: entity 名转换
'----------------------------------------------------------------
' getEntityLogicName
' 测试: 使用 entity 的物理名来获取 entity 的逻辑名
Private Sub test_SeparateOneSheetEntityManager_getEntityLogicName()
    Dim em As ISqlEntityManager
    Set em = create_SeparateOneSheetEntityManager

    Debug.Assert em.getEntityLogicName("table2") = "XXXB"
    Debug.Assert em.getEntityLogicName("table9") = "XXXI"
    Debug.Assert em.getEntityLogicName("") = ""
    Debug.Assert em.getEntityLogicName("tablexxxxxxx") = ""
End Sub

' getEntityPhyName
' 测试: 使用 entity 的逻辑名来获取 entity 的物理名
Private Sub test_SeparateOneSheetEntityManager_getEntityPhyName()
    Dim em As ISqlEntityManager
    Set em = create_SeparateOneSheetEntityManager

    Debug.Assert em.getEntityPhyName("XXXB") = "table2"
    Debug.Assert em.getEntityPhyName("XXXI") = "table9"
    Debug.Assert em.getEntityPhyName("") = ""
    Debug.Assert em.getEntityPhyName("tablexxxxxxx") = ""
End Sub

'----------------------------------------------------------------
' 测试: item 名转换
'----------------------------------------------------------------
' getItemPhyName
' 测试: 使用 item 逻辑名，获取 item 物理名
Private Sub test_SeparateOneSheetEntityManager_getItemPhyName()
    Dim em As ISqlEntityManager
    Set em = create_SeparateOneSheetEntityManager

    ' item 逻辑名 + entity 物理名
    Debug.Assert em.getItemPhyName("AN2", "table1") = "apn2"
    Debug.Assert em.getItemPhyName("BN2", "table2") = "bpn2"
    Debug.Assert em.getItemPhyName("", "") = ""
    Debug.Assert em.getItemPhyName("tablexxxxxxx", "table2") = ""
    Debug.Assert em.getItemPhyName("BN2", "tablexxxxxxxx") = ""

    ' item 逻辑名 + entity 逻辑名
    Debug.Assert em.getItemPhyName("AN2", "XXXA") = "apn2"
    Debug.Assert em.getItemPhyName("BN2", "XXXB") = "bpn2"
    Debug.Assert em.getItemPhyName("", "") = ""
    Debug.Assert em.getItemPhyName("tablexxxxxxx", "table2") = ""
    Debug.Assert em.getItemPhyName("BN2", "tablexxxxxxxx") = ""
End Sub

' getItemPhyNameByEntityPhyName
' 测试: 使用 item 逻辑名 + entity 物理名，获取 item  物理名
Private Sub test_SeparateOneSheetEntityManager_getItemPhyNameByEntityPhyName()
    Dim em As ISqlEntityManager
    Set em = create_SeparateOneSheetEntityManager

    Debug.Assert em.getItemPhyNameByEntityPhyName("AN2", "table1") = "apn2"
    Debug.Assert em.getItemPhyNameByEntityPhyName("BN2", "table2") = "bpn2"
    Debug.Assert em.getItemPhyNameByEntityPhyName("", "") = ""
    Debug.Assert em.getItemPhyNameByEntityPhyName("tablexxxxxxx", "table2") = ""
    Debug.Assert em.getItemPhyNameByEntityPhyName("BN2", "tablexxxxxxxx") = ""
End Sub

' getItemPhyNameByEntityLogicName
' 测试: 使用 item 逻辑名 + entity 逻辑名，获取 item 物理名
Private Sub test_SeparateOneSheetEntityManager_getItemPhyNameByEntityLogicName()
    Dim em As ISqlEntityManager
    Set em = create_SeparateOneSheetEntityManager

    Debug.Assert em.getItemPhyNameByEntityLogicName("AN2", "XXXA") = "apn2"
    Debug.Assert em.getItemPhyNameByEntityLogicName("BN2", "XXXB") = "bpn2"
    Debug.Assert em.getItemPhyNameByEntityLogicName("", "") = ""
    Debug.Assert em.getItemPhyNameByEntityLogicName("tablexxxxxxx", "table2") = ""
    Debug.Assert em.getItemPhyNameByEntityLogicName("BN2", "tablexxxxxxxx") = ""
End Sub

' getItemLogicName
' 测试: 使用 item 物理名获取 item 逻辑名
Private Sub test_SeparateOneSheetEntityManager_getItemLogicName()
    Dim em As ISqlEntityManager
    Set em = create_SeparateOneSheetEntityManager

    ' item 物理名 + entity 物理名
    Debug.Assert em.getItemLogicName("apn2", "table1") = "AN2"
    Debug.Assert em.getItemLogicName("bpn2", "table2") = "BN2"
    Debug.Assert em.getItemLogicName("", "") = ""
    Debug.Assert em.getItemLogicName("tablexxxxxxx", "table2") = ""
    Debug.Assert em.getItemLogicName("bpn2", "tablexxxxxxxx") = ""

    ' item 物理名 + entity 逻辑名
    Debug.Assert em.getItemLogicName("apn1", "XXXA") = "AN1"
    Debug.Assert em.getItemLogicName("apn2", "XXXA") = "AN2"
    Debug.Assert em.getItemLogicName("bpn2", "XXXB") = "BN2"
    Debug.Assert em.getItemLogicName("", "") = ""
    Debug.Assert em.getItemLogicName("tablexxxxxxx", "table2") = ""
    Debug.Assert em.getItemLogicName("bpn2", "tablexxxxxxxx") = ""
End Sub

' getItemLogicNameByEntityPhyName
' 测试: 使用 item 物理名 + entity 逻辑名，获取 item 逻辑名
Private Sub test_SeparateOneSheetEntityManager_getItemLogicNameByEntityPhyName()
    Dim em As ISqlEntityManager
    Set em = create_SeparateOneSheetEntityManager

    Debug.Assert em.getItemLogicNameByEntityPhyName("apn2", "table1") = "AN2"
    Debug.Assert em.getItemLogicNameByEntityPhyName("bpn2", "table2") = "BN2"
    Debug.Assert em.getItemLogicNameByEntityPhyName("", "") = ""
    Debug.Assert em.getItemLogicNameByEntityPhyName("tablexxxxxxx", "table2") = ""
    Debug.Assert em.getItemLogicNameByEntityPhyName("bpn2", "tablexxxxxxxx") = ""
End Sub

' getItemLogicNameByEntityLogicName
' 测试: 使用 item 物理名 + entity 物理名，获取 item 逻辑名
Private Sub test_SeparateOneSheetEntityManager_getItemLogicNameByEntityLogicName()
    Dim em As ISqlEntityManager
    Set em = create_SeparateOneSheetEntityManager

    Debug.Assert em.getItemLogicNameByEntityLogicName("apn2", "XXXA") = "AN2"
    Debug.Assert em.getItemLogicNameByEntityLogicName("bpn2", "XXXB") = "BN2"
    Debug.Assert em.getItemLogicNameByEntityLogicName("", "") = ""
    Debug.Assert em.getItemLogicNameByEntityLogicName("tablexxxxxxx", "table2") = ""
    Debug.Assert em.getItemLogicNameByEntityLogicName("bpn2", "tablexxxxxxxx") = ""
End Sub

'----------------------------------------------------------------
' 测试: item 名称类型检查
'----------------------------------------------------------------
' 检查当前的 item 是不是逻辑名
Private Sub test_SeparateOneSheetEntityManager_isLogicItemNameByEntityLogicName()
    Dim em As ISqlEntityManager
    Set em = create_SeparateOneSheetEntityManager

    Debug.Assert em.isLogicItemNameByEntityLogicName("AN1", "XXXA") = True
    Debug.Assert em.isLogicItemNameByEntityLogicName("apn1", "XXXA") = False
    Debug.Assert em.isLogicItemNameByEntityLogicName("apn1", "ZZZZ") = False
End Sub

' 检查当前的 item 是不是物理名
Private Sub test_SeparateOneSheetEntityManager_isPhyItemNameByEntityPhyName()
    Dim em As ISqlEntityManager
    Set em = create_SeparateOneSheetEntityManager

    Debug.Assert em.isPhyItemNameByEntityPhyName("apn1", "table1") = True
    Debug.Assert em.isPhyItemNameByEntityPhyName("AN1", "table1") = False
    Debug.Assert em.isPhyItemNameByEntityPhyName("ipn2", "table9") = True
End Sub

'--------------------------------------------
' 获取 item 名称
'--------------------------------------------
' 获取 item 物理名 + 使用 entity 物理名
Private Sub test_SeparateOneSheetEntityManager_getItemPhyNames_by_entityPhyName()
    Dim em As ISqlEntityManager
    Set em = create_SeparateOneSheetEntityManager

    Dim itemNames As IPrimitiveArrayRef
    Set itemNames = em.getItemPhyNames("table1")

    Debug.Assert itemNames.Count = 2
    Debug.Assert itemNames.Item(0) = "apn1"
    Debug.Assert itemNames.Item(1) = "apn2"
End Sub

' 获取 item 物理名 + 使用 entity 逻辑名
Private Sub test_SeparateOneSheetEntityManager_getItemPhyNames_by_entityLogicName()
    Dim em As ISqlEntityManager
    Set em = create_SeparateOneSheetEntityManager

    Dim itemNames As IPrimitiveArrayRef
    Set itemNames = em.getItemPhyNames("XXXA")

    Debug.Assert itemNames.Count = 2
    Debug.Assert itemNames.Item(0) = "apn1"
    Debug.Assert itemNames.Item(1) = "apn2"
End Sub

' 获取 item 逻辑名 + 使用 entity 物理名
Private Sub test_SeparateOneSheetEntityManager_getItemLogicNames_by_entityPhyName()
    Dim em As ISqlEntityManager
    Set em = create_SeparateOneSheetEntityManager

    Dim itemNames As IPrimitiveArrayRef
    Set itemNames = em.getItemLogicNames("table1")

    Debug.Assert itemNames.Count = 2
    Debug.Assert itemNames.Item(0) = "AN1"
    Debug.Assert itemNames.Item(1) = "AN2"
End Sub

' 获取 item 逻辑名 + 使用 entity 逻辑名
Private Sub test_SeparateOneSheetEntityManager_getItemLogicNames_by_entityLogicName()
    Dim em As ISqlEntityManager
    Set em = create_SeparateOneSheetEntityManager

    Dim itemNames As IPrimitiveArrayRef
    Set itemNames = em.getItemLogicNames("XXXA")

    Debug.Assert itemNames.Count = 2
    Debug.Assert itemNames.Item(0) = "AN1"
    Debug.Assert itemNames.Item(1) = "AN2"
End Sub
